package puzzle
{
	import flash.filters.ColorMatrixFilter;
	
	import org.wak.action.IInteractable;
	import org.wak.character.AdventureCharacter;
	import org.wak.character.display.AbstractCharacterDisplay;
	import org.wak.character.display.AnimationBehaviour;
	import org.wak.inventory.InventoryItem;
	import org.wak.main.AdventureMaster;
	import org.wak.main.PuzzleControllerBase;
	import org.wak.scene.ISceneInteractable;
	import org.wak.scene.Scene;
	import org.wak.scene.SceneItem;
	
	public class MyPuzzleController extends PuzzleControllerBase
	{
		private var rLum:Number = 0.2225;
		private var gLum:Number = 0.7169;
		private var bLum:Number = 0.0606;  
		
		
		// this is just for fun
		private var bwMatrix:Array = [rLum, gLum, bLum, 0, 0,
			rLum, gLum, bLum, 0, 0,
			rLum, gLum, bLum, 0, 0,
			0, 0, 0, 1, 0];  
		private var mColorFilter:ColorMatrixFilter ;   
		
		public function MyPuzzleController()
		{
			super();
			mColorFilter = new ColorMatrixFilter(bwMatrix);
		}
		
		
		//Interacting with stage items, picking things up, talking to characters etc.
		public function InteractSIGrogmachine(pItem1:ISceneInteractable):void
		{
			mDialogMngr.StartDialog("DChat");
			EndOfAction();
		}
		
		public function InteractSIShovel(pItem:SceneItem):void
		{
			var fPlyrChar:AdventureCharacter = mCharactersMngr.GetPlayerCharacter() ;
			mDialogMngr.SetOptionVisible("DFirstChat","TWho",true);
			trace("PickupLIShovel");
			
			
			var fPickupShovel:Function = function():void
			{
				fPlyrChar.characterDisplay.SetAnimBehaviour(AnimationBehaviour.STANDING_LEFT,1);
				var fScene:Scene = mSceneMngr.GetScene( pItem.sceneId );
				fScene.RemoveInteractable(pItem);
				
				var fNewIItem:InventoryItem = mInventoryMngr.GetInventoryItem("IShovel");
				fPlyrChar.inventory.AddItem(fNewIItem);
				
				EndOfAction();
			}
			
			fPlyrChar.characterDisplay.SetAnimBehaviour("pickupdown",1,fPickupShovel);
			
		}
		
		//Using inventory items with stage items. 
		//INVENTORY ITEMS SHOULD HAVE THE ID PREFIX I.
		//Awesome.
		public function UseIGoldAndSIGrogmachine(pItem1:IInteractable, pItem2:ISceneInteractable):void
		{
			var fPlyrChar:AdventureCharacter = mCharactersMngr.GetPlayerCharacter() ;
			
			var fGrogmachine:ISceneInteractable = pItem2 as ISceneInteractable ;
			
			
			var fOnPlayed:Function = function():void
			{
				fPlyrChar.characterDisplay.SetAnimBehaviour( pItem2.interactionBehaviour );
				fPlyrChar.Say("It ate my gold!");
				EndOfAction();
			}
			fPlyrChar.characterDisplay.SetAnimBehaviour("pickupup",2,fOnPlayed);
			
			
		}
		
		public function PickupSISword(pItem:SceneItem):void
		{
			var fPlyrChar:AdventureCharacter = mCharactersMngr.GetPlayerCharacter() ;
			EndOfAction();
			
		}
		
		public function InteractSIBox(pItem:SceneItem):void
		{
			var fPlyrChar:AdventureCharacter = mCharactersMngr.GetPlayerCharacter() ;
			
			EndOfAction();
			
		}
		
		public function InteractSISword(pItem:SceneItem):void
		{
			var fPlyrChar:AdventureCharacter = mCharactersMngr.GetPlayerCharacter() ;
			fPlyrChar.characterDisplay.SetAnimBehaviour( pItem.interactionBehaviour );
			
			trace("PushSISword");
			pItem.SetView("fliped");
			
			fPlyrChar.characterDisplay.filters = [mColorFilter] ;
			fPlyrChar.Say("Now I can be a Tim Burton's character.");
			EndOfAction();
		}
		
		public function PullSISword(pItem:SceneItem):void
		{
			var fPlyrChar:AdventureCharacter = mCharactersMngr.GetPlayerCharacter() ;
			trace("PushSISword");
			pItem.SetView("default");
			
			fPlyrChar.characterDisplay.filters = null ;
			fPlyrChar.Say("Much better");
			
			EndOfAction();
		}
		
		public function LookatIBook(pItem:IInteractable):void
		{
			mDialogMngr.CharacterSay( AdventureMaster.defaultPlayerCharacterId, "Heeellloouuuuuu there. meaning that the left margin of the text field remains fixed and any resizing of a single line of the text field is on the right margin. If the text includes a line break");
			EndOfAction() ;
		}
		
		//NOTES
		//the function naming goes as follows for custom
		//for interactable single scene items:
		//InteractITEMID(pItem:ISceneInteractable):void
		//InteractCHARACTERID((pItem:AbstractCharacterDisplay):void
		//WHY THE FUCK IS THIS NOT DETAILED ANYWHERE!
		
		public function InteractGuybrushClone(pItem:AbstractCharacterDisplay):void
		{
			trace("TalktoGuybrushClone:"+pItem);
			
			var fPlyrChar:AdventureCharacter = mCharactersMngr.GetPlayerCharacter() ;
			fPlyrChar.characterDisplay.SetAnimBehaviour( pItem.interactionBehaviour );
			mDialogMngr.StartDialog("DFirstChat");
			
			EndOfAction();
		}
		
		public function UseIKnifeAndGuybrushClone(pItem1:IInteractable, pItem2:IInteractable):void
		{
			var fPlyrChar:AdventureCharacter = mCharactersMngr.GetPlayerCharacter() ;
			fPlyrChar.characterDisplay.SetAnimBehaviour( AnimationBehaviour.STANDING_LEFT );
			
			mDialogMngr.CharacterSay( AdventureMaster.defaultPlayerCharacterId, "I don't hate myself that much.");
			EndOfAction();
		}
		
		public function GetChicken():void
		{
			trace("Puzzle controller, giving chicken");
			var fPlyrChar:AdventureCharacter = mCharactersMngr.GetPlayerCharacter() ;
			var fChicken:InventoryItem = mInventoryMngr.GetInventoryItem("IChicken");
			
			if(!fPlyrChar.inventory.HasItem(fChicken) )
				fPlyrChar.inventory.AddItem(fChicken);
			
		}
		
		public function OpenANightSky(pItem1:IInteractable):void
		{
			var fPlyrChar:AdventureCharacter = mCharactersMngr.GetPlayerCharacter() ;
			fPlyrChar.characterDisplay.SetAnimBehaviour( AnimationBehaviour.STANDING_RIGHT );
			
			mDialogMngr.CharacterSay( AdventureMaster.defaultPlayerCharacterId, "What?!");
			EndOfAction();
		}
		
		
		
		public function EnterSceneroad(pSceneId:String):void
		{
			trace("entering "+ pSceneId );
		}
		
		public function EnterSceneforestRight(pSceneId:String):void
		{
			trace("entering "+ pSceneId );
		}
		
		public function ExitSceneroad(pSceneId:String):void
		{
			trace("exiting "+ pSceneId );
		}
	}
}